/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package insulinpumpsimulation.com.his.tasks;

import insulinpumpsimulation.com.his.literal.InsulinPumpLiterals;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * We are assuming that day is of 720 seconds i.e. 12 minutes
 * @author Arun
 */
public class BasalManager {
   
   
  GregorianCalendar date = new GregorianCalendar();
  int second = date.get(Calendar.SECOND);
  int minute = date.get(Calendar.MINUTE);
  int hour = date.get(Calendar.HOUR_OF_DAY);
  int timeSinceDayStart =  3600 * hour + minute *60 + second;
  private static boolean excerciseMode;
 
  public void setExcerciseMode(Boolean eBoolean)
  {
      excerciseMode = eBoolean;
  }
  
  public double getBasalRate(){
      
    double dosePumpedPerBasalShot = InsulinPumpLiterals.MAXIMUM_DAILY_DOSE/(2*24);
    if (excerciseMode)
    {
        dosePumpedPerBasalShot = dosePumpedPerBasalShot/2;
    }
    int simulationPeriod = InsulinPumpLiterals.SIMULATION_PERIOD;
    int daySlot =   timeSinceDayStart  % InsulinPumpLiterals.SIMULATION_PERIOD;
    int firstSlot = simulationPeriod/6;
    int secondSlot = firstSlot + simulationPeriod/4;
    int thirdSlot = secondSlot + simulationPeriod/3;
    int fourthSlot = thirdSlot + simulationPeriod/4;
    
      System.out.println(daySlot+"::" +firstSlot+"::" +secondSlot+"::" +thirdSlot+"::" +fourthSlot);
       if(daySlot >= 0 &&  daySlot < simulationPeriod/6)
  {
      return dosePumpedPerBasalShot/2;
      
  }
        if(daySlot >= firstSlot  &&  daySlot < secondSlot)
  {
      return dosePumpedPerBasalShot * 1.5;
  }
          if(daySlot >=  secondSlot &&  daySlot <  thirdSlot)
  {
      return dosePumpedPerBasalShot;
  }
            if(daySlot >=  thirdSlot &&  daySlot <  fourthSlot)
  {
      return  dosePumpedPerBasalShot;
  }
       return 0;
  }
  
}
